package com.servlet;

import net.sf.json.JSONArray;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet(name = "ShoppingServlet", value = "/ShoppingServlet")
public class ShoppingServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/json;charset=utf-8");
        int uid = Integer.parseInt(request.getParameter("userid"));
        System.out.println("购物车页面请求"+uid);
        selectIdLog  shopp = new selectIdLog();
        try {
         JSONArray list = shopp.selectshopp(uid);

         //request.setAttribute("result","111");
           // request.setAttribute("stuList","22222");
         //request.getRequestDispatcher("JSP/Shopping.jsp").forward(request, response);
            String data = String.valueOf(list);
            response.getWriter().write(data);
         System.out.println("购物车界面数据加载完成");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}
